
#ifndef __KEY_H
#define __KEY_H

#include "../iface/debug.h"
#include "../iface/CryptInterface.h"

#define RSA_BITS 2048
#define AES_BITS 256
#define DSA_BITS 1024
#define ECDSA_BITS 521

/** A generic cryptographic key class. */
class Key
{
   public:
      enum keytypetype { KEY_TYPE_KEY           = 0,
                         KEY_TYPE_PUBLIC_RSA    = 1,
                         KEY_TYPE_PRIVATE_RSA   = 2,
                         KEY_TYPE_PUBLIC_DSA    = 3,
                         KEY_TYPE_PRIVATE_DSA   = 4,
                         KEY_TYPE_PUBLIC_ECDSA  = 5,
                         KEY_TYPE_PRIVATE_ECDSA = 6,
                         KEY_TYPE_SYMM_AES      = 7,
                         KEY_TYPE_SYMM_DES      = 8   };
      enum keypairtype { KEY_NULL_PAIR,
                         KEY_ASYMMETRIC_PAIR_RSA,
                         KEY_ASYMMETRIC_PAIR_DSA,
                         KEY_ASYMMETRIC_PAIR_ECDSA,
                         KEY_SYMMETRIC_AES };
      virtual ~Key();
      /** Import a key from some plain text. */
      virtual int importKeyFromASCII(const char *text, const char *name) = 0;
      /** Export a key to some plain text. */
      virtual int exportKeyToASCII(char **text) = 0;
      /** Import a key from some encrypted and passworded text. */
      virtual int importKeyFromASCIIWithPassword(const char *text, const char *password, const char *name) = 0;
      /** Export a key to some encrypted and passworded text. */
      virtual int exportKeyToASCIIWithPassword(char **text, const char *password) = 0;
      /** Determines whether the key is asymmetric or not, so this returns
       * non-zero if it is not it's own decryption key. */
      virtual int isAsymmetricKey() = 0;
      virtual int getKeyType();
      virtual const char *getKeyTypeFullName();
      virtual const char *getKeyTypeAbbrName();
      virtual const char *getKeyName();
      virtual void setKeyName(const char *tname);
   protected:
      // Be careful, public virtual inheritance can be broken!
      /** A pointer to the string containing the name of the key. */
      const char *keyname;
      /** The list of key type names for debugging and error messages. */
      static const char *key_type_names[];
      /** The list of abbreviated key type names for databases. */
      static const char *key_type_abbrs[];
};

#endif
